<?php
/**
 *
 * @Author nikm $
 *
 * @Date 2012-3-10 $
 */

if(!defined('FROM_INDEX')) exit('Invalid request');

date_default_timezone_set('Asia/Shanghai');

define('ADODB_PATH', ROOT_PATH.'lib/adodb5/');

define('STAGE', 'devl');

function load_setting($filename, $name='')
{
	$file = ROOT_PATH.'config/'.$filename.'.php';
	
	if(!is_file($file))
	{
		exit("Setting file '".$file."' does not exists!");
	}
	
	include $file;
	
	if(is_array($setting))
	{
		if($name && isset($setting[$name]))
		{
			if(is_array($setting[$name]))
			{
				foreach($setting[$name] as $k=>$v)
				{
					if(!defined(strtoupper($k))) define(strtoupper($k), $v);
				}
			}
			else
			{
				if(!defined(strtoupper($name))) define(strtoupper($name), $setting[$name]);
			}
		}
		else
		{
			foreach($setting as $k=>$v)
			{
				if(is_array($v))
				{
					foreach($v as $sk=>$sv)
					{
						if(!defined(strtoupper($sk))) define(strtoupper($sk), $sv);
					}
				}
				else
				{
					if(!defined(strtoupper($k))) define(strtoupper($k), $v);
				}
			}
		}
	}
	
	return '';
}